package demo1;

import org.w3c.dom.css.CSSUnknownRule;

/**
 * @ClassDescription:
 * @JdkVersion: 1.8
 * @Author: 李白
 * @Created: 2024/4/10 22:35
 */
class Animal{//父类
    protected String name;
    public int age;
    static {
        System.out.println("Animal:静态");
    }
    {
        System.out.println("Animal:实例");
    }

    public Animal() {
    }

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("吃饭");
    }

    public void eat(){
        System.out.println(this.name+" 正在吃饭！");
    }
}

//==================================================
class Dog extends Animal{//Dog类继承了Animal，子类、派生类
    static {
        System.out.println("Dog:静态");
    }
    {
        System.out.println("Dog:实例");
    }
    public Dog(String name,int age){
        super(name,age);//和this语句一样，只能在第一行,如果把这行代码屏蔽，则默认调用无参数的父类构造方法，然后因为无参数，所以输出也是无参数
        System.out.println(this.name+" "+this.age);//虽然在子类构造方法里面调用了
    }

    /**
     * 子类会默认提供一个构造函数，引用父类的构造方法
     */
    /*public Dog(){
        super();
    }*/
    public void bark(){
        System.out.println(this.name+" 正在汪汪叫");
    }
}
//================================
class Cat extends Animal{
    public Cat(){
        super();
    }

    public Cat(String name, int age) {
        super(name, age);//Cat方法里的形参作为输入给与给父类对应构造方法的形参
    }

    public void miaomiao(){
        System.out.println(this.name+"正在喵喵叫");
    }
}
public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog("wangwu",10);
    }








    public static void main1(String[] args) {
        /*Derived derived = new Derived();
        derived.test1();*/
        Dog dog = new Dog("wangwu",10);
        dog.bark();
        dog.eat();
        System.out.println("============");
        Cat cat = new Cat("lisi",20);
        cat.miaomiao();
        cat.eat();
    }
}







//==============================
class Base{//父类
    int a = 10;
    public void method(){
        System.out.println("method");
    }
}
////////
class Derived extends Base{//子类
    int a = 100;
    public void method1(){
        System.out.println("method1");
    }
    public void test1(){
        method1();
        super.method();
        System.out.println(a);
        System.out.println(super.a);
    }
    public void method(){
        System.out.println("Derived:method");
    }
    public Derived(){//构造方法

    }
}


